<?php
/*
 * Template Name: Template Product
 */
?>
<?php get_header(); ?>
<div id="box">
    <div id="container">        
        <div id="content">
            <div id="product">
                <?php
                $taxonomy = 'cat-product';
                $post_type = 'product';
                $term_args = array(
                    'orderby' => 'name',
                    'order' => 'ASC'
                );
                $taxonomies = get_terms($taxonomy, $term_args);
                if ($taxonomies) {
                    foreach ($taxonomies as $tax) {
                        ?>
                        <div class="tit-pro"><h3><?php echo $tax->name; ?></h3></div>
                        <ul class="items-pro">
                            <?php
                            $loop = new WP_Query(array(
                                'post_type' => $post_type,
                                'tax_query' => array(
                                    array(
                                        'taxonomy' => $taxonomy,
                                        'field' => 'slug',
                                        'terms' => $tax->slug,
                                        'posts_per_page' => '12'
                                    )
                                )
                            ));
                            if ($loop->have_posts()) {
                                $i = 1;
                                while ($loop->have_posts()):$loop->the_post();
                                    if ($i % 4 == 1) {
                                        ?>                            
                                        <li class="item-pro">
                                            <ul>
                                            <?php } ?>
                                            <li>
                                                <a href="<?php the_permalink(); ?>">
                                    <?php the_post_thumbnail(); ?></a>
                                                <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?> 
                                                    </a></p>
                                                
                                            </li>
                                            <?php
                                            if ($i % 4 == 0) {
                                                ?> 
                                                <div class="clear"></div></ul><div class="hr"></div></li>
                                        <?php
                                    }
                                    $i++;
                                endwhile;
                                if ($i % 4 == 0 || $i % 4 == 2 || $i%4==3) {
                                    ?> 
                                    <div class="clear"></div>
                                </ul>
                                </li>
                                <?php
                            }
                        }
                        ?>
                        </ul>
                        <?php
                    }
                }
                ?>                 
            </div>            
        </div>
        <div id="sidebar">
            <? get_sidebar(); ?>
        </div>
        <div class="clear"></div>
        <div id="bottom">
            <div class="l">
                <h4>SEAWEALTH VN COMPANY LIMITED</h4>
                <p>Address: 121 LY Tu Trong Street, 3 ward, Vung  Tau city, Viet Nam</p>
                <p>Phone: 0646 250 579 - 568 - 679</p>
                <p>Email: info@namviet-it.com</p> 
            </div>
            <div class="r" style="width: 50%">
                <?php
                wp_nav_menu(array(
                    'theme_location' => 'secondary-menu',
                    'menu_id' => 'bot-nav')
                );
                ?> 
                <div class="r">
                    <p class="r">Copyright 2013 by <a href="http://localhost/seafood/">http://seawealthvn.com.</a> Allright Reserved.</p>
                    <p class="r">Design by <a href="http://namviet-it.com">namviet</a></p>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
            </div>
            <div class="clear"></div>

        </div>  
    </div>
</div>
<?php get_footer(); ?>